
public class test2 {
    //力扣  67.二进制求和
    public static void main(String[] args) {
        String str1 = "11";
        String str2 = "1";
        System.out.println(addBinary(str1, str2));
        char[] chars = {'a','b','v'};

    }
    public static String addBinary(String a, String b) {
        if(a.length()==0 || b.length()==0) return a;
        char[] chara = a.toCharArray();
        char[] charb = b.toCharArray();
        int len = chara.length>charb.length?chara.length:charb.length;
        StringBuilder ret = new StringBuilder();
        char[] retarr = new char[len];

        int key = 0;
        int cur1 = chara.length-1,cur2 = charb.length-1;
        while (true) {
            //第一个字符串
            if(cur1>=0){
                key+=chara[cur1]-'0';
                cur1--;
            }
            //第二个字符串
            if(cur2>=0){
                key+=charb[cur2]-'0';
                cur2--;
            }
            ret.append(key%2);
            key/=2;
            if(cur1<0 && cur2<0){
                break;
            }
        }
        if(key!=0){
            ret.append(key%2);

        }
        StringBuilder reverse = ret.reverse();
        return reverse.toString();
    }
}
